import router from "./index";
import store from "@/store";
const whiteList = ['/about']
// 路由前置守卫
router.beforeEach((to, form, next)=>{
  // 判断跳转的路由是否有权限
  store.dispatch('GetUesrInfo').then(()=>{
    if(JSON.parse(localStorage.getItem('userInfo'))?.routers.indexOf(to.path) !== -1 && whiteList.indexOf(to.path) !== -1) {
      next()
    }else if(to.path !== '/login' && !JSON.parse(localStorage.getItem('userInfo'))?.userInfo.token) {
      // 判断没有token跳转其他路由拦截
      next({ path: '/login' });
    } else {
      next();
    }
  })
  // 判断跳转的路由是否有权限路由或白名单
  // if(whiteList.indexOf(to.path) !== -1) {
  //   next()
  // } else if(to.path !== '/login' && !JSON.parse(localStorage.getItem('userInfo'))?.userInfo.token) {
  //   // 判断没有token跳转其他路由拦截
  //   next({ path: '/login' });
  // } else {
  //   next();
  // }
});

// router.afterEach(()=>{

// })